package com.zdkj.subway.check.controller.subwayRat.cashboxUninstallController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zdkj.common.core.util.R;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.check.service.impl.subwayRat.cashboxUninstall.CashboxUninstallServiceImpl;
import com.zdkj.subway.check.util.LineOrStation;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.zdkj.subway.check.util.JdbcUtil;
import com.zdkj.subway.check.result.Result;
import com.zdkj.subway.check.enums.ResultDetailMsg;
import org.springframework.security.access.prepost.PreAuthorize;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 报表差错信息
 */
@RestController
@RequestMapping("/check")
@Slf4j
public class CashboxUninstallController {

    @Autowired
    private CashboxUninstallServiceImpl cashboxUninstallService;

	/**
	 * 钱箱未卸载
	 * @param page
	 * @param param
	 * @return
	 */
    @RequestMapping("/getCashboxUninstallList")
	@ApiOperation(value = "钱箱未卸载",notes = "钱箱未卸载")
    public R getCashboxUninstallList(com.baomidou.mybatisplus.extension.plugins.pagination.Page page,@RequestParam Map<String,String> param){
        Map<String,Object> p=new HashMap<>(param);
		String moneyBoxType = param.get("moneyBoxType");
		if(moneyBoxType!=null && !"".equals(moneyBoxType)){
		   if(moneyBoxType.equals("1")){
               p.put("moneyBoxType","硬币回收箱");

		   }else if(moneyBoxType.equals("2")){
			   p.put("moneyBoxType","硬币找零箱");

		   }else if(moneyBoxType.equals("3")){
			    p.put("moneyBoxType","纸币回收箱");

		   }else if(moneyBoxType.equals("4")){
			    p.put("moneyBoxType","纸币找零箱");

		   }else if(moneyBoxType.equals("5")){
			    p.put("moneyBoxType","废钞箱");

		   }
		}
        /*List<Map<String, Object>> cashboxUninstallList = cashboxUninstallService.getCashboxUninstallList(p);
        page.setData(cashboxUninstallList,true);
        return page;*/
		PigxUser user = SecurityUtils.getUser();
		//区分是否是线网人员
		if(user.getBelongToLine()){
			List lineList = LineOrStation.getmanagementLine();
			p.put("lines",lineList);
		}else{
			List lineList = LineOrStation.getLineOrManagementLine();
			p.put("lines",lineList);
		}
		//查询钱箱未卸载
		IPage<Map<String, Object>> cashboxUninstallList = cashboxUninstallService.getCashboxUninstallList(page,p);
        return R.ok(cashboxUninstallList);
    }

	 /**
     * 高级删除
     * 删除钱箱未卸载(逻辑删除，只是改变状态)
     * @param swStReportErrorAlterApply
     * @return
     */
    @RequestMapping("/highDelCashBox")
    @ApiOperation(value = "删除钱箱未卸载(逻辑删除，只是改变状态)", notes = "删除钱箱未卸载(逻辑删除，只是改变状态)")
    //@PreAuthorize("@pms.hasPermission('sw_st_input_cashbox_uninstalled_highdel')")
    public Result highDelCashBox(String ids){       
        Result result=new Result(ResultDetailMsg.OK);
        try {
            String[] strIds = ids.split(",");
			StringBuilder sb = new StringBuilder();
			for(int i=0;i<strIds.length;i++){
			   if(i!=0){
			     sb.append(",");
			   }
			   sb.append(strIds[i]);
			}
			String sql  = "update sw_st_input_cashbox_uninstalled set del_flag='1' where id in("+sb.toString()+")";
			//log.info("钱箱未卸载高级删除SQL ===="+ sql);
            JdbcUtil.exeSqlCrud(sql);
           
        }catch (Exception e){
            log.error("{}",e);
            result.setResult(ResultDetailMsg.CHECK_UPDATE_ERROR);
			result.appendMsg("未删除数据");
        }
        return result;
    }

}
